<template>
  <el-container style="height: 100vh">
    <el-aside width="250px">
      <!-- :default-openeds="['1']" -->
      <el-menu router
        :default-active="$route.path"
        style="height: 100vh;"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        unique-opened
        >
        <el-submenu index="1">
          <template slot="title"><i class="el-icon-coordinate"></i>分类管理</template>
          <el-menu-item-group>
            <el-menu-item index="/categories/create">新建分类</el-menu-item>
            <el-menu-item index="/categories/list">分类列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title"><i class="el-icon-suitcase"></i>物品管理</template>
          <el-menu-item-group>
            <el-menu-item index="/items/create">新建物品</el-menu-item>
            <el-menu-item index="/items/list">物品列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title"><i class="el-icon-suitcase"></i>英雄管理</template>
          <el-menu-item-group>
            <el-menu-item index="/heroes/create">新建英雄</el-menu-item>
            <el-menu-item index="/heroes/list">英雄列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="4">
          <template slot="title"><i class="el-icon-suitcase"></i>文章管理</template>
          <el-menu-item-group>
            <el-menu-item index="/articles/create">新建文章</el-menu-item>
            <el-menu-item index="/articles/list">文章列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="5">
          <template slot="title"><i class="el-icon-suitcase"></i>广告位管理</template>
          <el-menu-item-group>
            <el-menu-item index="/ads/create">新建广告位</el-menu-item>
            <el-menu-item index="/ads/list">广告位列表</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <h1 style="display:inline;font-size:28px;">王者荣耀官网移动端后台管理页面</h1>
        <div style="float: right; font-size: 12px">
          <el-dropdown split-button trigger="click" @click="$router.push('/')">
            <!-- <i class="el-icon-setting" style="margin-right: 15px"></i> -->
            {{ username }}
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item><span @click="$router.push('/admin_users/list')">查看</span></el-dropdown-item>
            <el-dropdown-item><span @click="$router.push('/admin_users/create')">新增</span></el-dropdown-item>
            <el-dropdown-item><span @click="loginout">退出</span></el-dropdown-item>
          </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <router-view :key="$route.path"></router-view>
        <div v-if="isNullPath">
          <h1 style="color:blue;font-size:40px;text-align:center;">这里是仿王者荣耀官网:移动端后台管理页面</h1>
          <p style="color:red;font-size:32px;text-align:center;"> 点击<a style=" text-decoration: none;" href="/">这里</a> 跳转到移动端页面</p>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>
<style>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }
  .el-aside {
    color: #333;
  }
  .el-dropdown-link {
    cursor: pointer;
    /* color: #409EFF; */
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>

<script>
export default {
  data () {
    return {
      username: '',
      isNullPath: false
    }
  },
  mounted () {
    this.username = localStorage.username
    if (this.$route.path === '/') {
      this.isNullPath = true
    }
  },
  watch: {
    $route (to, from) {
      if (!(this.$route.path === '/')) {
        this.isNullPath = false
      } else {
        this.isNullPath = true
      }
    }
  },
  methods: {
    loginout () {
      this.$msgbox({
        title: '提示',
        message: '确定退出吗',
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            instance.confirmButtonText = '退出中...'
            setTimeout(() => {
              done()
              this.$router.push('/login')
              localStorage.clear()
              instance.confirmButtonLoading = true
              setTimeout(() => {
                instance.confirmButtonLoading = false
              }, 300)
            }, 1000)
          } else {
            done()
          }
        }
      })
    }
  }
}
</script>
